﻿<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@ include file="/WEB-INF/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>管家常后台管理系统</title>
	<link href="${ctx}/resource/system/admin/css/style.css" rel="stylesheet"/>
	<style>
	.login_top p {height: 120px;line-height: 120px;text-align: center;font-size: 30px;letter-spacing: 4px;color: darkgray;}
	</style>
	<script src="${ctx}/resource/system/admin/js/jquery-1.7.2.js" type="text/javascript"></script>
	<script src="${ctx}/resource/system/admin/js/public.js"></script>
	<!--[if lte IE 7]><link rel="stylesheet" src="${ctx}/resource/system/admin/css/elusive-webfont-ie7.css" /><![endif]-->
	<!--[if lte IE 7]><script src="${ctx}/resource/system/admin/js/lte-ie7.js"></script><![endif]-->

	<script type="text/javascript">
		$(document).keydown(function(event) {
			if(event.keyCode==13) {
				formsubmit();
			}
		});
	
		function formsubmit() {
			var username = $("#loginForm").find("input[name=username]").val();
			var password = $("#loginForm").find("input[name=password]").val();
			var validate = $("#loginForm").find("input[name=validate]").val();
			var success = true;
			$("#errorMsg").empty();
			
			if($.trim(username) == ""){
				$("input[name=username]").focus();
				$("input[name=username]").select();
				$("#errorMsg").html("请输入用户名！");
				success =false;
			}else if(password == ""){
				$("input[name=password]").focus();
				$("input[name=password]").select();
				$("#errorMsg").html("请输入密码！");
				success =false; 
			}else if(validate == ""){
				$("input[name=validate]").focus();
				$("input[name=validate]").select();
				$("#errorMsg").html("请输入验证码！");
				success =false;
			}
			
			if(success){
				$.post("${ctx}/admin/administrator/login.json",
					  {username:username,password:password,validate:validate},
					  function(result){
						    result = eval("("+result+")");
							if(result.status == "true" || result.status == true){
								window.location.href="${ctx}/admin/administrator/index.htm";	
							}else {
								if(result.msg == "验证码错误！"){
									$("#errorMsg").html(result.msg);
									$("input[name=validate]").focus();
									$("input[name=validate]").select();
									refresh();
								}else if(result.msg == "用户名或密码错误"){
									$("#errorMsg").html(result.msg);
									$("input[name=password]").focus();
									$("input[name=password]").select();
								}
							}
					  });
			}
		}
		
		function refresh() {
		    $("#validateImg").attr("src", "${ctx}/public/image/validateImg.htm?"+Math.random()); 
		}
	</script>
</head>

<body style="background:url(${ctx}/resource/system/admin/images/contentBg.jpg) repeat;">
	<div class="login">
    	<div class="login_top"><p>后台管理系统</p><!--<img src="${ctx}/resource/system/admin/images/logo.png" />--></div>
    	<div style="text-align: center;color: #FD4343" id="errorMsg"></div>
    	<form id="loginForm" onsubmit="return false;">
        	<div class="username"><input type="text" placeholder="用户名"  name="username" maxlength="20"/></div>
            <div class="password"><input type="password" placeholder="密码"  name="password" maxlength="20"/></div>
            <div class="erwm"><input type="text" placeholder="验证码" name="validate" maxlength="4"/>
            	<img  id="validateImg" src="${ctx}/public/image/validateImg.htm" title="看不清，点击刷新" style="cursor: pointer;" onclick="refresh();" />
            </div>
            <div class="loginBtn"><a href="javascript:void(0);" onclick="formsubmit();" >登  录</a></div>
        </form>
    </div>
</body>
</html>